package com.clwl.supervise.superviseapp.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 弃用，在filter中进行了文件转发
 */
@Deprecated
//@Configuration
public class WebResourceConfig implements WebMvcConfigurer {


   

    @Value("${app.fileSuffixs}")
    private String fileSuffixs;


    private  String fileUploadActive;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //String uploadPath = StringUtils.equals(fileUploadActive, "dev") ? FileUploadUtil.devUploadPath :StrUtil.blankToDefault(SpringUtil.getBean(SysConfigMapper.class).queryByKey("SYS_CONFIG_ROOT_PATH").getParamValue(), "/home/files/clwlkb/");
        //String uploadBucket = StringUtils.equals(FileUploadUtil.fileUploadActive, "dev") ? FileUploadUtil.devUploadBucket : StrUtil.blankToDefault(SpringUtil.getBean(SysConfigMapper.class).queryByKey( FileUploadUtil.minioBucketKey).getParamValue(), FileUploadUtil.devUploadBucket);
        //String fileServer = StringUtils.equals(FileUploadUtil.fileUploadActive, "dev") ? FileUploadUtil.devUploadPath : StrUtil.blankToDefault(SpringUtil.getBean(SysConfigMapper.class).queryByKey(FileUploadUtil.minioUrlKey).getParamValue(),  FileUploadUtil.devUploadPath);
        //适应新监管平台文件路径
        String[] fileSuffixArr = fileSuffixs.split(",");
        for (String fileSuffix : fileSuffixArr) {
//            registry.addResourceHandler("/files/**/*."+fileSuffix).addResourceLocations(fileServer) ;
//            registry.addResourceHandler("/**/*."+fileSuffix).addResourceLocations(fileServer) ;
//            registry.addResourceHandler("/*."+fileSuffix).addResourceLocations(fileServer) ;
            //registry.addResourceHandler("**/*."+fileSuffix).addResourceLocations(fileServer) ;
        }

    }


    @Value("${spring.profiles.file_upload_active}")
    public void setFileUploadActive(String fileUploadActive) {
        this.fileUploadActive = fileUploadActive;
    }

}
